package com.yonyou.brigade.rtpnr.model;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.yonyou.ybzboot.uc.dto.UcUserDto;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * <p>
 * <p>
 * </p>
 *
 * @author jiangzhf@yonyou.com
 * @since 2018-06-12
 */
@TableName("rtpnr_user")
public class RtpnrUser extends Model<RtpnrUser> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    /**
     * 用户userid
     */
    @TableField("user_id")
    private String userId;
    /**
     * 用户手机号
     */
    private String mobile;
    /**
     * 用户名
     */
    @TableField("user_name")
    private String userName;
    /**
     * Y激活 N非激活
     */
    @TableField("is_activation")
    private String isActivation;
    /**
     * 身份证号
     */
    @TableField("card_no")
    private String cardNo;
    /**
     * 身份证姓名
     */
    @TableField("card_name")
    private String cardName;
    /**
     * 邮箱地址
     */
    private String email;

    /**
     * 组织PK
     */
    @TableField("org_pk")
    private String orgpk;

    /**
     * 租户ID
     */
    private String tenant;
    /**
     * 部门注：为空或"/"则默认到企业总部下面,多部门之间用"/"分割，例如部门是差旅研发组，则这样表示（/研发中心/差旅研发组）
     */
    private String department;

    /**
     * 返回的userkey
     */
    @TableField("f_user_key")
    private String fUserKey;

    /**
     * 登录账号
     */
    @TableField("f_login_id")
    private String fLoginId;

    /**
     * 员工编号
     */
    @TableField("staff_num")
    private String staffNum;

    /**
     * 员工等级
     */
    @TableField("category")
    private String category;

    @TableField("pub_account")
    private String pubAccount;

    private Integer admin;

    private Date ts;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getIsActivation() {
        return isActivation;
    }

    public void setIsActivation(String isActivation) {
        this.isActivation = isActivation;
    }

    public String getCardNo() {
        return cardNo;
    }

    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }

    public String getCardName() {
        return cardName;
    }

    public void setCardName(String cardName) {
        this.cardName = cardName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getOrgpk() {
        return orgpk;
    }

    public void setOrgpk(String orgpk) {
        this.orgpk = orgpk;
    }

    public String getfUserKey() {
        return fUserKey;
    }

    public void setfUserKey(String fUserKey) {
        this.fUserKey = fUserKey;
    }

    public String getfLoginId() {
        return fLoginId;
    }

    public void setfLoginId(String fLoginId) {
        this.fLoginId = fLoginId;
    }

    public String getTenant() {
        return tenant;
    }

    public void setTenant(String tenant) {
        this.tenant = tenant;
    }

    public Integer getAdmin() {
        return admin;
    }

    public void setAdmin(Integer admin) {
        this.admin = admin;
    }

    public String getStaffNum() {
        return staffNum;
    }

    public void setStaffNum(String staffNum) {
        this.staffNum = staffNum;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getPubAccount() {
        return pubAccount;
    }

    public void setPubAccount(String pubAccount) {
        this.pubAccount = pubAccount;
    }

    public Date getTs() {
        return ts;
    }

    public void setTs(Date ts) {
        this.ts = ts;
    }

    public static final String ID = "id";

    public static final String USER_ID = "user_id";

    public static final String MOBILE = "mobile";

    public static final String USER_NAME = "user_name";

    public static final String IS_ACTIVATION = "is_activation";

    public static final String CARD_NO = "card_no";

    public static final String CARD_NAME = "card_name";

    public static final String EMAIL = "email";

    public static final String DEPARTMENT = "department";

    public static final String TS = "ts";

    public static final String TENANT = "tenant";

    public static final String ORGPK = "org_pk";

    public static final String PUB_ACCOUNT = "pub_account";

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    @Override
    public String toString() {
        return "RtpnrUser{" +
                "id=" + id +
                ", userId=" + userId +
                ", mobile=" + mobile +
                ", userName=" + userName +
                ", isActivation=" + isActivation +
                ", cardNo=" + cardNo +
                ", cardName=" + cardName +
                ", email=" + email +
                ", department=" + department +
                ", ts=" + ts +
                "}";
    }


    public boolean toCompareUcUserDto(UcUserDto ucUserDto) {
        boolean equal = true;
        if (StringUtils.isEmpty(userId)) {
            if (!StringUtils.isEmpty(ucUserDto.getUserId())) {
                return false;
            }
        } else {
            if (!userId.equals(ucUserDto.getUserId())) {
                return false;
            }
        }

        if (StringUtils.isEmpty(userName)) {
            if (!StringUtils.isEmpty(ucUserDto.getUserName())) {
                return false;
            }
        } else {
            if (!userName.equals(ucUserDto.getUserName())) {
                return false;
            }
        }


        if (StringUtils.isEmpty(mobile)) {
            if (!StringUtils.isEmpty(ucUserDto.getPhone())) {
                return false;
            }
        } else {
            if (!mobile.equals(ucUserDto.getPhone())) {
                return false;
            }
        }

        if (StringUtils.isEmpty(email)) {
            if (!StringUtils.isEmpty(ucUserDto.getEmail())) {
                return false;
            }
        } else {
            if (!email.equals(ucUserDto.getEmail())) {
                return false;
            }
        }

        if (StringUtils.isEmpty(department)) {
            if (!StringUtils.isEmpty(ucUserDto.getDeptName())) {
                return false;
            }
        } else {
            // 如果是公户则部门由公司和部门拼接
            if ("1".equals(pubAccount) && !department.equals(ucUserDto.getOrgName() + "/" + ucUserDto.getDeptName())) {
                return false;
            } else if ("0".equals(pubAccount) && !department.equals(ucUserDto.getDeptName())) {
                return false;
            }
        }

        if (StringUtils.isEmpty(staffNum)) {
            if (!StringUtils.isEmpty(ucUserDto.getPersonCode())) {
                return false;
            }
        } else {
            if (!staffNum.equals(ucUserDto.getPersonCode())) {
                return false;
            }
        }

        if (StringUtils.isEmpty(category)) {
            if (!StringUtils.isEmpty(ucUserDto.getRankName())) {
                return false;
            }
        } else {
            if (!category.equals(ucUserDto.getRankName())) {
                return false;
            }
        }

        if (StringUtils.isEmpty(orgpk)) {
            if (!StringUtils.isEmpty(ucUserDto.getOrgPk())) {
                return false;
            }
        } else {
            if (!orgpk.equals(ucUserDto.getOrgPk())) {
                return false;
            }
        }

        if (StringUtils.isEmpty(isActivation)) {
            return false;
        } else {
            if (isActivation.equals("Y") && ucUserDto.getDr().intValue() != 0) {
                return false;
            }
            if (isActivation.equals("N") && ucUserDto.getDr().intValue() == 0) {
                return false;
            }
        }

        return equal;
    }
}
